package org.game.porker.porker24.mybatis.pojo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class Porker {
	private static final String path = "/images/veryhuo.com_pkp_"; //地址前段
	private String ownPath;//地址中段
	private int number;//点数
	
	public static List<Porker> porkers;//52张牌
	static {
		porkers = new ArrayList<Porker>();
		String [] codes = {"bp", "bm", "rp", "rd"};
		for (int i = 1; i <= 13; i++) {
			for (String cd : codes) {
				Porker p = new Porker("" + i + cd, i);
				porkers.add(p);
			}
		}
	}
	
	/*public static final Porker ONE_BLK_PEA = new Porker("1bp", 1);
	public static final Porker ONE_BLK_MEI = new Porker("1bm", 1);
	public static final Porker ONE_RED_PEA = new Porker("1rp", 1);
	public static final Porker ONE_RED_DIA = new Porker("1rd", 1);
	
	public static final Porker TWO_BLK_PEA = new Porker("2bp", 2);
	public static final Porker TWO_BLK_MEI = new Porker("2bm", 2);
	public static final Porker TWO_RED_PEA = new Porker("2rp", 2);
	public static final Porker TWO_RED_DIA = new Porker("2rd", 2);
	
	public static final Porker THREE_BLK_PEA = new Porker("3bp", 3);
	public static final Porker THREE_BLK_MEI = new Porker("3bm", 3);
	public static final Porker THREE_RED_PEA = new Porker("3rp", 3);
	public static final Porker THREE_RED_DIA = new Porker("3rd", 3);
	
	public static final Porker FOUR_BLK_PEA = new Porker("4bp", 4);
	public static final Porker FOUR_BLK_MEI = new Porker("4bm", 4);
	public static final Porker FOUR_RED_PEA = new Porker("4rp", 4);
	public static final Porker FOUR_RED_DIA = new Porker("4rd", 4);
	
	public static final Porker FIVE_BLK_PEA = new Porker("5bp", 5);
	public static final Porker FIVE_BLK_MEI = new Porker("5bm", 5);
	public static final Porker FIVE_RED_PEA = new Porker("5rp", 5);
	public static final Porker FIVE_RED_DIA = new Porker("5rd", 5);
	
	public static final Porker SIX_BLK_PEA = new Porker("6bp", 6);
	public static final Porker SIX_BLK_MEI = new Porker("6bm", 6);
	public static final Porker SIX_RED_PEA = new Porker("6rp", 6);
	public static final Porker SIX_RED_DIA = new Porker("6rd", 6);
	
	public static final Porker SEVEN_BLK_PEA = new Porker("7bp", 7);
	public static final Porker SEVEN_BLK_MEI = new Porker("7bm", 7);
	public static final Porker SEVEN_RED_PEA = new Porker("7rp", 7);
	public static final Porker SEVEN_RED_DIA = new Porker("7rd", 7);
	
	public static final Porker EIGHT_BLK_PEA = new Porker("8bp", 8);
	public static final Porker EIGHT_BLK_MEI = new Porker("8bm", 8);
	public static final Porker EIGHT_RED_PEA = new Porker("8rp", 8);
	public static final Porker EIGHT_RED_DIA = new Porker("8rd", 8);
	
	public static final Porker NINE_BLK_PEA = new Porker("9bp", 9);
	public static final Porker NINE_BLK_MEI = new Porker("9bm", 9);
	public static final Porker NINE_RED_PEA = new Porker("9rp", 9);
	public static final Porker NINE_RED_DIA = new Porker("9rd", 9);
	
	public static final Porker TEN_BLK_PEA = new Porker("10bp", 10);
	public static final Porker TEN_BLK_MEI = new Porker("10bm", 10);
	public static final Porker TEN_RED_PEA = new Porker("10rp", 10);
	public static final Porker TEN_RED_DIA = new Porker("10rd", 10);
	
	public static final Porker J_BLK_PEA = new Porker("11bp", 11);
	public static final Porker J_BLK_MEI = new Porker("11bm", 11);
	public static final Porker J_RED_PEA = new Porker("11rp", 11);
	public static final Porker J_RED_DIA = new Porker("11rd", 11);
	
	public static final Porker Q_BLK_PEA = new Porker("12bp", 12);
	public static final Porker Q_BLK_MEI = new Porker("12bm", 12);
	public static final Porker Q_RED_PEA = new Porker("12rp", 12);
	public static final Porker Q_RED_DIA = new Porker("12rd", 12);
	
	public static final Porker K_BLK_PEA = new Porker("13bp", 13);
	public static final Porker K_BLK_MEI = new Porker("13bm", 13);
	public static final Porker K_RED_PEA = new Porker("13rp", 13);
	public static final Porker K_RED_DIA = new Porker("13rd", 13);*/
	
	private Porker(String path, int number) {
		// TODO Auto-generated constructor stub
		this.ownPath = path;
		this.number = number;
	}

	public String getOwnPath() {
		return ownPath;
	}

	public int getNumber() {
		return number;
	}
	//获取全地址
	public String getPathForDisplay() {
		return path + ownPath + ".jpg";
	}
	
	public static List<Porker> getRandom4Porkers() {
		Map<String, Porker> map = new HashMap<String, Porker>();
		Random r = new Random();
		while(map.keySet().size() < 4) {
			int i = r.nextInt(porkers.size());//52张牌中随机抽取一张
			Porker p = porkers.get(i);//获取牌的信息
			while (map.containsKey(p.getOwnPath())) {//判断获取信息是否已存在map中
				i = r.nextInt(porkers.size());//重新随机抽取
				p = porkers.get(i);//重新获取信息
			}
			map.put(p.getOwnPath(), p);//牌信息存储在map中
		}
		List<Porker> ret = new ArrayList<Porker>();
		ret.addAll(map.values());//将map中的牌信息添加到list中
		return ret;
	}
 
}
